package service

import (
	"context"
	__ "video-srv/basic/proto"
	"video-srv/handle/model"
)

type Server struct {
	__.UnimplementedVideoServer
}

func (s *Server) AddVideo(_ context.Context, in *__.AddVideoReq) (*__.AddVideoResp, error) {

	var video model.Video

	video = model.Video{
		UserId:    int32(in.UserId),
		Title:     in.Title,
		VideoType: in.VideoType,
		VideoTag:  in.VideoTag,
		ImageUrl:  in.ImageUrl,
		VideoUrl:  in.VideoUrl,
	}

	err := video.AddVideo()
	if err != nil {
		return nil, err
	}

	return &__.AddVideoResp{VideoId: int64(video.Id)}, nil
}

func (s *Server) UpdateProtobuf(_ context.Context, in *__.UpdateProtobufReq) (*__.UpdateProtobufResp, error) {

	var protobuf model.Protobuf

	protobuf = model.Protobuf{
		VideoId:        int32(in.VideoId),
		ProtobufUserId: int32(in.ProtobufUserId),
		Content:        in.Content,
		Status:         int8(in.Status),
	}

	err := protobuf.UpdateProtobuf()
	if err != nil {
		return nil, err
	}

	var video model.Video

	video.Id = uint32(in.VideoId)
	video.Status = int8(in.Status)
	err = video.UpdateVideo()
	if err != nil {
		return nil, err
	}

	return &__.UpdateProtobufResp{VideoId: int64(protobuf.VideoId)}, nil
}
